package cn.edu.neusoft.neufooddemo.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.neufooddemo.R;
import cn.edu.neusoft.neufooddemo.activity.FoodDetailActivity;
import cn.edu.neusoft.neufooddemo.bean.FoodInfo;
import cn.edu.neusoft.neufooddemo.common.Constants;

public class FoodListAdapter extends RecyclerViewAdapter<FoodListAdapter.ViewHolder> {
    private String phonenum;
    public FoodListAdapter(Context context, List data, int layoutResource) {
        super(context, data, layoutResource);
    }
    public FoodListAdapter(Context context, List data, int layoutResource,String phonenum) {
        super(context, data, layoutResource);
        this.phonenum=phonenum;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final FoodInfo entity = (FoodInfo)data.get(position);
        holder.food_foodname.setText(entity.getFoodname());
        holder.food_price.setText(entity.getPrice()+"元");
        holder.food_intro.setText(entity.getIntro());
        if(!entity.getPic().equals("")){
            Picasso.get().load(Constants.BASE_URL+entity.getPic()).into(holder.food_pic);

        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //               Intent intent = new Intent(context, FoodInfoActivity.class);
               Intent intent = new Intent(context, FoodDetailActivity.class);
                intent.putExtra("id",entity.getFood_id());
                intent.putExtra("phonenum",phonenum);
                context.startActivity(intent);
            }
        });
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView food_pic;
        TextView food_foodname,food_price,food_intro;

        public ViewHolder(View itemView) {
            super(itemView);
            food_foodname = (TextView) itemView.findViewById(R.id.food_foodname);
            food_pic = (ImageView) itemView.findViewById(R.id.food_pic);
            food_price = (TextView) itemView.findViewById(R.id.food_price);
            food_intro = (TextView) itemView.findViewById(R.id.food_intro);
        }
    }
}

